package com.scau.controller;

import com.scau.dao.HomeworkDao;
import com.scau.dao.MessageDao;
import com.scau.dao.StudentDao;
import com.scau.dao.VideoDao;
import com.scau.dao.Impl.HomeworkDaoImpl;
import com.scau.dao.Impl.MessageDaoImpl;
import com.scau.dao.Impl.StudentDaoImpl;
import com.scau.dao.Impl.VideoDaoImpl;
import com.scau.mapper.SectionMapper;
import com.scau.mapper.StudentMapper;
import com.scau.pojo.Homework;
import com.scau.pojo.Message;
import com.scau.pojo.Messagecomment;
import com.scau.pojo.Section;
import com.scau.pojo.Student;
import com.scau.pojo.Video;
import com.scau.util.SqlSessionFactoryUtil;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class Test {
	
	@RequestMapping("/testSection")
    public  int testSection(){
        SqlSession session = SqlSessionFactoryUtil.getSession();
        SectionMapper sectionMapper=session.getMapper(SectionMapper.class);
        Section section=new Section();
        section.setSeName("111");
        section.setSePpt("111");
        section.setSeSeq(1);
        section.settId(3);
        
		return sectionMapper.insert(section);
    }
	@RequestMapping("/testStu")
    public  String testStudent(){
        StudentDao studentdao=new StudentDaoImpl();
        Student student=new Student();
//        student.setStGrade("2011");
//		student.setStMajor("2011");
//		student.setStName("2011");
//		student.setStPassword("2011");
//		student.setStSchool("2011");
//		student.setStSex("2011");
//		student.setStTel("2011");
//		student.setStValidation(1);
//		student.setStTest(1);
        Map<String,Object> result=studentdao.getStudentByName("111");
		if((int)result.get("returnCode")==1){
			student=(Student)result.get("student");
			return student.getStSchool();
		}else{
			return "用户不存在！";
		}
        
    }
	@RequestMapping("/testVideo")
    public  String testVideo(){
        HomeworkDao hwdao=new HomeworkDaoImpl();
        Homework homework=new Homework();
        homework.sethModifytime(new Date());
        homework.sethName("DuJianYan");
        homework.sethReleasetime(new Date());
        homework.setSeId(1);
        int count=hwdao.add(homework);
        System.out.println(count);
		return "success";
    }
	
	@RequestMapping("/testMessage")
    public  Message testMsg(){
		int seId=6;
		Message mm=new Message();
		MessageDao msgdao=new MessageDaoImpl();
		List<Message> msgs=msgdao.queryBySeId(seId);
		for (Message m : msgs) {
			mm=m;
			break;
		}
		return mm;
		
    }
	
}
